﻿using Microsoft.EntityFrameworkCore;
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
using System;

namespace Idiom.Models
{
    public class IdiomContext : DbContext
    {

        public IdiomContext() : base()
        {

        }
        protected override void OnConfiguring(DbContextOptionsBuilder dbContextOptionsBuilder)
        {
            dbContextOptionsBuilder.UseMySql("Server=47.103.17.132;Database=Muke;User=root;Password=As179345036;", mySqlOptions => mySqlOptions
                       .ServerVersion(new Version(5, 7, 29), ServerType.MySql));


        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {

            modelBuilder.Entity<IdiomModel>().Property(b => b.Character).IsRequired();
            modelBuilder.Entity<Sentence>().Property(b => b.SentenceContent).IsRequired();
            modelBuilder.Entity<IdiomModel>().HasMany(i => i.ExampleSentence).WithOne(s => s.Blong);
            // modelBuilder.Entity<Sentence>().HasOne(p => p.Blong).WithMany(b=>b.ExampleSentence);
            modelBuilder.Entity<IdiomModel>().HasMany(i => i.Similars).WithOne();
            modelBuilder.Entity<IdiomModel>().HasMany(i => i.Relevants).WithOne();
            // modelBuilder.Entity<Relevant>().HasOne(r => r.Belong).WithMany();
            // modelBuilder.Entity<Similar>().HasOne(s => s.Belong).WithMany();


        }

        public DbSet<IdiomModel> IdiomModels { get; set; }
        public DbSet<Sentence> Sentences { set; get; }
        public DbSet<Similar> Similas { set; get; }
        public DbSet<Relevant> Relevants { set; get; }
    }
}
